package io.kimmking.dubbo.demo.second.consumer.controller;

import io.kimmking.dubbo.common.service.CustomerService;
import io.kimmking.dubbo.common.service.OrderService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
//@EnableAutoConfiguration
@RefreshScope
@RequestMapping("/secondConsumer")
public class Second_consumer_Controller {

    @Value("${second_consumer_value:1111}")
    private String value;

    @DubboReference(version = "1.0.0")
    CustomerService customerService;

    @DubboReference(version = "1.0.0")
    OrderService orderService;

    @RequestMapping("/getUserAndOrderInfo")
    public List<String> getUserAndOrderInfo(){
        return customerService.list().stream()
                .map(e -> e.toString())
                .collect(Collectors.toList());
    }

    @RequestMapping("/canalOrder/{orderNo}")
    public void canalOrder(@PathVariable(value = "orderNo") String orderNo){
        orderService.deleteOrder(orderNo);
    }
}
